home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / elv18src.zip / doc / init.ms < prev    next >
Text File  |  1994-01-16  |  5KB  |  134 lines

  1. .Go 6 "INITIALIZATION"
  2. .PP
  3. Many features of \*E are configurable at runtime.
  4. There are commands for assigning actions to keys (:map),
  5. defining abbreviations (:abbr),
  6. non-ASCII keying sequences (:digraph),
  7. setting screen colors (:color),
  8. and miscellaneous other options (:set).
  9. .PP
  10. All of these commands can be issued interactively.
  11. Experienced vi users generally prefer to have some options set
  12. every time they run they execute \*E,
  13. and \*E has ways to support this.
  14. .LP
  15. .SH
  16. Start-up Initialization
  17. .PP
  18. When \*E starts, it executes the following algorithm in an attempt
  19. to locate initialization commands:
  20. .ID
  21.  
  22. If this version of \*E supports a system-wide initialization
  23. file and that file exists,
  24.     Interpret that file's contents as a series of "ex" commands
  25.  
  26. If the EXINIT environment variable is set
  27.     Interpret the value of EXINIT as an "ex" command line.
  28. Else if the home directory contains a file named ".exrc"
  29.     Interpret that file's contents as a series of "ex" commands
  30.  
  31. If the "exrc" option is set, and the current directory contains
  32. a file named ".exrc"
  33.     Interpret that file's contents as a series of "ex" commands
  34.  
  35. If a tag was specified via a "-t" command line argument,
  36.     Execute a tag look-up, and load file if successful
  37.  
  38. If no tag was specified, or the specified tag wasn't found,
  39.     Load the first file named on the command line, or
  40.     start empty buffer.
  41.  
  42. If a command was specified via "+command" or "-c command"
  43.     Execute the given command.
  44. .DE
  45. .PP
  46. Note that most of this initialization occurs before the first file is loaded.
  47. Consequently, commands which examine or change the edit buffer can't be used
  48. there.
  49. Only "+command" or "-c command" is executed after the text file has been loaded.
  50. .PP
  51. On non-UNIX systems, ".exrc" is usually an invalid filename so the file is
  52. called "ELVIS.RC" instead.
  53. Also, the home directory is the directory named by the HOME environment
  54. variable;
  55. on DOS and a few other systems, if HOME is unset then \*E will use the
  56. directory which contains the executable file (ELVIS.EXE) as your home
  57. directory.
  58. .LP
  59. .SH
  60. File Initialization
  61. .PP
  62. Loading a file, too, can cause commands to be executed.
  63. Each time any file is loaded into the edit buffer, the following
  64. algorithm is used to locate file-specific initialization commands.
  65. .ID
  66.  
  67. Fill the edit buffer with the file's contents, and set various options
  68. and variables accordingly.
  69.  
  70. If the home directory contains a file involves  named ".exfilerc"
  71.     Interpret the contents of that file as a series of "ex" commands.
  72.  
  73. If the "modelines" option is set,
  74.     Search the first 5 & last 5 lines of the text for lines which
  75.     contain "ex:<command>:" or "vi:<command>:", and interpret any
  76.     <command> as an "ex" command line.
  77. .DE
  78. .PP
  79. On non-UNIX systems, ".exfilerc" is usually an invalid filename, so the file
  80. is called "EXFILE.RC" instead.
  81. .LP
  82. .SH
  83. The :mkexrc Command
  84. .PP
  85. \*E has a special command, ":mkexrc [filename]", to help you create ".exrc"
  86. files.
  87. It creates a file which sets all nonstandard options, maps, and so on.
  88. .PP
  89. By default, the created file's name will be ".exrc" in the current directory.
  90. You can either add ":set exrc" to the .exrc file in your home directory
  91. to force \*E to read this new .exrc in your current directory,
  92. or you can move this new .exrc file into your home directory.
  93. .PP
  94. Alternatively, you can supply an explicit filename as an argument to :mkexrc.
  95. .PP
  96. Afterward, you may wish to edit the created file.
  97. For example, some options may be conditional;
  98. the :mkexrc file doesn't distinguish between options which were set 
  99. unconditionally from those that were set in a text file's modelines
  100. or other conditional context.
  101. .PP
  102. Warning: the :mkexrc command will happily overwrite any file that you tell
  103. it to, if your operating system permits.
  104. .LP
  105. .SH
  106. Other Techniques
  107. .PP
  108. \*E has commands for conditional execution, but the standard vi doesn't.
  109. If you often use the real vi, you may want to avoid \*E's extensions.
  110. To have a terminal-dependent initialization file, you can add
  111. ":so $HOME/.exrc.$TERM" to the end of your .exrc file, and then create
  112. files with names like ".exrc.vt100" and ".exrc.ansi" in your home directory
  113. which contain the terminal-dependent commands.
  114. .PP
  115. Another good technique is to write a shell-script "wrapper" around \*E/vi.
  116. Here's one of my favorites.
  117. It uses "grep" to locate files containing a given regular expression,
  118. and then starts vi on those files
  119. with the cursor positioned on the first occurrence in the first file.
  120. I call this script "vg".
  121. .ID
  122.  
  123. #!/bin/sh
  124. case "$#" in
  125.   0)    echo "usage: vg regexp [files]..." >&2; exit;;
  126.   1)    set -- "$1" *.[ch];;
  127. esac
  128.  
  129. regexp="$1"
  130. shift
  131.  
  132. vi +/"$regexp" `grep -l "$regexp" "$@"`
  133. .DE
  134.